package com.wp.land.api;

import com.wp.land.context.VDataContext;
import com.wp.land.entity.qrcode.QRChangeData;
import com.wp.land.entity.qrcode.QRData;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/05/09
 * @Modified By:
 */
@RestController
@RequestMapping("/api/")
public class QrCodeApi {

    /**
     * 扫描设置显示值   1.花生，2绿茶
     * @param index
     * @return
     */
    @RequestMapping(value = "/qr/{index}", method = RequestMethod.GET)
    public Object setQrIndex(@PathVariable String index){

        Map params = new HashMap(4);
        Objects.requireNonNull(index,"index 不能为空");

//        if (!VDataContext.list_qr_index.contains(index)){
//            params.put("success",false);
//            return params;
//        }
        //重置数据
        if (index.equals("0")){
            VDataContext.isStart = true;
            return "0";
        }

        int _index =  Integer.parseInt(index);
        QRData qrData = VDataContext.list_QRData.get(_index-1);

        params.put("success",true);
        params.put("data",qrData);

        VDataContext.qrIndex = _index;
        VDataContext.isStart = false;
        return params;
    }


    /**
     * 获取显示值
     * @param index
     * @return
     */
    @RequestMapping(value = "/qrdata/{index}", method = RequestMethod.GET)
    public Object getQrData(@PathVariable String index){

        Objects.requireNonNull(index,"index 不能为空");

        List listReturn = new ArrayList(16);

        QRData qrData = VDataContext.list_QRData.get(VDataContext.qrIndex-1);

        Map params = new HashMap(16);

        // 第一行
        if (index.equals("11")){
            params.put("name","");
            params.put("value",qrData.getWdName());
        } else if (index.equals("12")){
            List list = qrData.getWdList();
            return list;
        }

        else if (index.equals("13")){
            params.put("name","");
            params.put("value",qrData.getSdName());
        } else if (index.equals("14")){
            List list = qrData.getSdList();
            return list;
        }

        else if (index.equals("15")){
            params.put("name","");
            params.put("value",qrData.getGzLeft());
        }else if (index.equals("16")){
            List list = qrData.getGzList();
            return list;
        }

        else if (index.equals("17")){
            params.put("name","");
            params.put("value",qrData.getJyLeft());
        }else if (index.equals("18")){
            List list = qrData.getJyList();
            return list;
        }
        // 图片
        else if (index.equals("21")){
            params.put("img",qrData.getImg());
            params.put("url",qrData.getUrl());
        }
        //得分匹配
        else if (index.equals("22")){
            List list = qrData.getTaskLeft();
            return list;
        }else if (index.equals("23")){
            List list = qrData.getTaskRight();
            return list;
        }

        else if (index.equals("24")){
            List list = qrData.getTableAvgList();
            return list;
        } else if (index.equals("25")){
            if (VDataContext.isStart){
                //默认值
                List<QRChangeData> qrChangeDatas = new ArrayList<>();
                qrChangeDatas.add(new QRChangeData("","名称：未知"));
                qrChangeDatas.add(new QRChangeData("","品种：未知"));
                qrChangeDatas.add(new QRChangeData("","适合种植地区：未知"));
                qrChangeDatas.add(new QRChangeData("","适宜土壤：未知"));
                qrChangeDatas.add(new QRChangeData("","播种期：未知"));
                qrChangeDatas.add(new QRChangeData("","建议施肥：未知"));
                return qrChangeDatas;
            }
            List list = qrData.getQrChangeDataList();
            return list;
        }

        else if (index.equals("31")){
            List list = qrData.getYsMatchList();
            return list;
        }
        else if (index.equals("32")){
            List list = qrData.getLandCompositionList();
            return list;
        }



        listReturn.add(params);

        return listReturn;
    }


}
